home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / bb / src / titlemod.c < prev   
Encoding:
C/C++ Source or Header  |  1994-06-01  |  8.4 KB  |  386 lines

  1. /*
  2.         title mode operation
  3.                       1993.6.27 v1.0
  4.                       copyright Y.Ouchi
  5. */
  6.  
  7. #include    <stdio.h>
  8. #include    <string.h>
  9. #include    <stdlib.h>
  10. #include    "egb.h"
  11. #include    "mos.h"
  12. #include    "bb.h"
  13.  
  14.     /* 関数プロトタイプ宣言 */
  15. extern    char    egbwork[];
  16. extern    char    moswork[];
  17. extern    void    linedsp(int, int, char *);
  18. extern    void    linedspv(int, int, char *, int, unsigned int, unsigned int);
  19. extern    void    box(int, int, int, int, int, int);
  20. extern    int        panelread(int, struct panel *, int);
  21.         void    lineset(char *, struct logcontent *, short *, int, char *);
  22.  
  23. extern    int        max_text;
  24. extern    int        dispmode;
  25.  
  26. int titlemod ( char *log, int leng, char **title,
  27.                     struct logcontent *intext, short *disptext, int *textno)
  28. {
  29.     int        i,k,flag,n;
  30.     char    logtitle[TITLE_LINE_NO][90];
  31.     char    logkind[TITLE_LINE_NO];
  32.     int        tcol;
  33.     int        pos=0;
  34.     int        result,action;
  35.     int        logindex;
  36.     char    *change_page={"▲  page up/down  ▼   ( use mouse bottan or pad trigger )"};
  37.     struct    panel    n_menu[1];
  38.  
  39.  
  40.                     /* page move char display */
  41.     EGB_writePage(egbwork,1);
  42.     linedsp( 6,52,change_page );
  43.     EGB_writePage(egbwork,0);
  44.  
  45.                     /* title display select */
  46.     MOS_horizon( 0,639 );
  47.     MOS_vertical( 35,448 );
  48.     MOS_setpos( 120, 60 );
  49.     MOS_disp( 1 );
  50.  
  51.     flag=1;
  52.     while ( flag ){
  53.  
  54.                     /* title dsiplay arrary make */
  55.         for (i=0;i<TITLE_LINE_NO;i++){
  56.             if ( *textno+i < max_text ){
  57.                 logindex=disptext[*textno+i];
  58.                 if (intext->text[logindex].text.id!=TITLE_ID){
  59.                     if (intext->text[logindex].text.leng>0){
  60.                         lineset(log,intext,disptext,*textno+i,logtitle[i]);
  61.                         logkind[i]=0;
  62.                     }
  63.                     else{
  64.                         logtitle[i][0]=0x00;
  65.                     }
  66.                 }
  67.                 else{
  68.                     strcpy(logtitle[i],
  69.                             title[intext->text[logindex].title.index]);
  70.                     logkind[i]=1;
  71.                 }
  72.             }
  73.             else{
  74.                 logtitle[i][0]=0x00;
  75.             }
  76.         }
  77.  
  78.         for (k=0;k<TITLE_LINE_NO;k++){
  79.             if (logkind[k]==0) tcol=TEXT_COL;
  80.             else tcol=NAME_COL;
  81.             linedspv ( 2, k*18+69, logtitle[k],0,tcol,BACK_COL);
  82.         }
  83.  
  84.         n_menu[0].xpos=0;
  85.         n_menu[0].ypos=35;
  86.         n_menu[0].xsize=640;
  87.         n_menu[0].ysize=414;
  88.         n_menu[0].xbtnsize=640;
  89.         n_menu[0].ybtnsize=18;
  90.         n_menu[0].ful=0;
  91.         n_menu[0].disp=0;
  92.         n_menu[0].ini_digit=0;
  93.         while ( (result = panelread (1, n_menu, 1)) >= 2000 );
  94.         if ( result<0 ) action=0;
  95.         else{
  96.             if ( result < 1000 ){
  97.                 action=1;
  98.                 pos=result;
  99.             }
  100.             else{
  101.                 action=2;
  102.                 pos=result-1000;
  103.             }
  104.         }
  105.  
  106.         switch ( action ){
  107.             case 0 :
  108.                 flag=0;
  109.                 MOS_disp( 0 );
  110.                 EGB_writePage(egbwork,1);
  111.                 box( 0,35,639,459,0,1 );
  112.                 EGB_writePage(egbwork,0);
  113.                 break;
  114.             case 1 :
  115.                 if ( pos==0 ){
  116.                     if (*textno+TITLE_LINE_NO < max_text)
  117.                             *textno=*textno+TITLE_LINE_NO;
  118.                 }
  119.                 else{
  120.                     *textno=*textno+pos-1;
  121.                     if ( *textno>max_text-1 ) *textno=max_text-1;
  122.                     if (intext->text[disptext[*textno]].title.id==TITLE_ID){
  123.                         for ( n=*textno;n<max_text-1;n++ ){
  124.                             if (intext->text[disptext[n]].text.id
  125.                                                     != TITLE_ID ) break;
  126.                         }
  127.                         *textno=n;
  128.                     }
  129.                     flag=0;
  130.                     MOS_disp( 0 );
  131.                     EGB_writePage(egbwork,1);
  132.                     box( 0,35,639,459,0,1 );
  133.                     EGB_writePage(egbwork,0);
  134.                 }
  135.                 break;
  136.             case 2 :
  137.                 if ( pos==0 ){
  138.                     *textno=*textno-TITLE_LINE_NO;
  139.                     if (*textno<0) *textno=0;
  140.                 }
  141.                 else{
  142.                     flag=0;
  143.                     MOS_disp( 0 );
  144.                     EGB_writePage(egbwork,1);
  145.                     box( 0,35,639,459,0,1 );
  146.                     EGB_writePage(egbwork,0);
  147.                     break;
  148.                 }
  149.                 break;
  150.         }
  151.         EGB_color(egbwork, 0, TEXT_COL);
  152.         EGB_clearScreen(egbwork);
  153.     }
  154.     MOS_disp( 0 );
  155.     EGB_color(egbwork, 0, TEXT_COL);
  156.     EGB_color(egbwork, 1, BACK_COL);
  157.  
  158.     return(0);
  159.  
  160. }
  161.  
  162. /*
  163.         display charactor set with comment level mark
  164. */
  165. void    lineset(char *log,struct logcontent *logc,
  166.                         short *dsp,int txtp,char *dest)
  167. {
  168.     int        i,j;
  169.     int        com;
  170.     char    *src;
  171.  
  172.     if (dispmode==NORMAL_MODE) com=0;
  173.     else com=logc->text[dsp[txtp]].text.com_lvl;
  174.     src=&(log[logc->text[dsp[txtp]].text.pos]);
  175.  
  176.     switch (abs(com)){
  177.         case 0 :
  178.             break;
  179.         case 1 :
  180.             dest[0]=0x84;
  181.             if (com>0) dest[1]=0xaf;
  182.             else dest[1]=0xb0;
  183.             break;
  184.         default :
  185.             for (i=0;i<(abs(com)-1)*2;i=i+2){
  186.  
  187.                 dest[i]=0x20;
  188.                 dest[i+1]=0x20;
  189.                 for (j=txtp-1;j>=0;j--){
  190.                     if (logc->text[dsp[j]].text.com_lvl==0){
  191.                         break;
  192.                     }
  193.                     if (abs(logc->text[dsp[j]].text.com_lvl)==(i+2)/2){
  194.                         if (logc->text[dsp[j]].text.com_lvl < 0){
  195.                             dest[i]=0x84;
  196.                             dest[i+1]=0xab;
  197.                         }
  198.                         else break;
  199.                     }
  200.                 }
  201.             }
  202.             dest[(abs(com)-1)*2]=0x84;
  203.             if (com>0) dest[(abs(com)-1)*2+1]=0xaf;
  204.             else dest[(abs(com)-1)*2+1]=0xb0;
  205.             break;
  206.     }
  207.  
  208.     if(com==0){
  209.         for (i=0;i<80;i++){
  210.             if (src[i]==0x0d && src[i+1]==0x0a){
  211.                 dest[i]=0x00;
  212.                 break;
  213.             }
  214.             else{
  215.                 dest[i]=src[i];
  216.             }
  217.         }
  218.     }
  219.     else{
  220.         for (i=0;i<80-abs(com)*2;i++){
  221.             if (src[i]==0x0d && src[i+1]==0x0a){
  222.                 dest[i+abs(com)*2]=0x00;
  223.                 break;
  224.             }
  225.             else{
  226.                 dest[i+abs(com)*2]=src[i];
  227.             }
  228.         }
  229.     }
  230.     dest[81]=0x00;
  231.     return;
  232. }
  233.  
  234.  
  235. int ttitlemod ( char *log, int leng, char **title,
  236.                     struct logcontent *intext, short *disptext, int *textno)
  237. {
  238.     int        i,k,flag,n;
  239.     char    logtitle[TITLE_LINE_NO][90];
  240.     char    logkind[TITLE_LINE_NO];
  241.     short    logno[TITLE_LINE_NO];
  242.     int        tcol;
  243.     int        workid;
  244.     int        pos=0;
  245.     int        result,action;
  246.     int        logindex;
  247.     char    *change_page={"▲  page up/down  ▼   ( use mouse bottan or pad trigger )"};
  248.     struct    panel    n_menu[1];
  249.  
  250.  
  251.                     /* page move char display */
  252.     EGB_writePage(egbwork,1);
  253.     linedsp( 6,52,change_page );
  254.     EGB_writePage(egbwork,0);
  255.  
  256.                     /* title display select */
  257.     MOS_horizon( 0,639 );
  258.     MOS_vertical( 35,448 );
  259.     MOS_setpos( 120, 60 );
  260.     MOS_disp( 1 );
  261.  
  262.     for (i=*textno;i>0;i--){
  263.         if (intext->text[disptext[i]].text.id==TITLE_ID ||
  264.             intext->text[disptext[i]].text.id==NOTITLE_TEXT_ID) break;
  265.     }
  266.     *textno=i;
  267.  
  268.     flag=1;
  269.     while ( flag ){
  270.  
  271.                     /* title dsiplay arrary make */
  272.         k=0;
  273.         i=0;
  274.         while ( *textno+k < max_text ){
  275.             logindex=disptext[*textno+k];
  276.             if (intext->text[logindex].text.id==TITLE_ID
  277.                     || intext->text[logindex].text.id==NOTITLE_TEXT_ID){
  278.                 strncpy(logtitle[i],
  279.                         &log[intext->text[logindex].title.pos],
  280.                         intext->text[logindex].title.lleng);
  281.                 logtitle[i][intext->text[logindex].title.lleng]=0x00;
  282.                 if (intext->text[logindex].text.id==TITLE_ID) logkind[i]=1;
  283.                 else logkind[i]=0;
  284.                 logno[i]=*textno+k;
  285.                 i=i+1;
  286.                 if (i>=TITLE_LINE_NO) break;
  287.             }
  288.             k=k+1;
  289.         }
  290.         while (i<TITLE_LINE_NO){
  291.             logtitle[i][0]=0x00;
  292.             logno[i]=max_text-1;
  293.             i=i+1;
  294.         }
  295.  
  296.         for (k=0;k<TITLE_LINE_NO;k++){
  297.             if (logkind[k]==0) tcol=TEXT_COL;
  298.             else tcol=NAME_COL;
  299.             linedspv ( 2, k*18+69, logtitle[k],0,tcol,BACK_COL);
  300.         }
  301.  
  302.         n_menu[0].xpos=0;
  303.         n_menu[0].ypos=35;
  304.         n_menu[0].xsize=640;
  305.         n_menu[0].ysize=414;
  306.         n_menu[0].xbtnsize=640;
  307.         n_menu[0].ybtnsize=18;
  308.         n_menu[0].ful=0;
  309.         n_menu[0].disp=0;
  310.         n_menu[0].ini_digit=0;
  311.         while ( (result = panelread (1, n_menu, 1)) >= 2000 );
  312.         if ( result<0 ) action=0;
  313.         else{
  314.             if ( result < 1000 ){
  315.                 action=1;
  316.                 pos=result;
  317.             }
  318.             else{
  319.                 action=2;
  320.                 pos=result-1000;
  321.             }
  322.         }
  323.  
  324.         switch ( action ){
  325.             case 0 :
  326.                 flag=0;
  327.                 MOS_disp( 0 );
  328.                 EGB_writePage(egbwork,1);
  329.                 box( 0,35,639,459,0,1 );
  330.                 EGB_writePage(egbwork,0);
  331.                 break;
  332.             case 1 :
  333.                 if ( pos==0 ){
  334.                     *textno=logno[TITLE_LINE_NO-1]+1;
  335.                     if (*textno >= max_text) *textno=logno[0];
  336.                 }
  337.                 else{
  338.                     *textno=logno[pos-1];
  339.                     if ( *textno>max_text-1 ) *textno=max_text-1;
  340.                     if (intext->text[disptext[*textno]].title.id==TITLE_ID){
  341.                         for ( n=*textno;n<max_text-1;n++ ){
  342.                             if (intext->text[disptext[n]].text.id
  343.                                                     != TITLE_ID ) break;
  344.                         }
  345.                         *textno=n;
  346.                     }
  347.                     flag=0;
  348.                     MOS_disp( 0 );
  349.                     EGB_writePage(egbwork,1);
  350.                     box( 0,35,639,459,0,1 );
  351.                     EGB_writePage(egbwork,0);
  352.                 }
  353.                 break;
  354.             case 2 :
  355.                 if ( pos==0 ){
  356.                     k=0;
  357.                     for (i=logno[0]-1;i>=0;i--){
  358.                         workid=intext->text[disptext[i]].text.id;
  359.                         if (workid==TITLE_ID || workid==NOTITLE_TEXT_ID) k=k+1;
  360.                         if (k>=TITLE_LINE_NO) break;
  361.                     }
  362.                     if (i<0) *textno=0;
  363.                     else *textno=i;
  364.                 }
  365.                 else{
  366.                     flag=0;
  367.                     MOS_disp( 0 );
  368.                     EGB_writePage(egbwork,1);
  369.                     box( 0,35,639,459,0,1 );
  370.                     EGB_writePage(egbwork,0);
  371.                     break;
  372.                 }
  373.                 break;
  374.         }
  375.         EGB_color(egbwork, 0, TEXT_COL);
  376.         EGB_clearScreen(egbwork);
  377.     }
  378.     MOS_disp( 0 );
  379.     EGB_color(egbwork, 0, TEXT_COL);
  380.     EGB_color(egbwork, 1, BACK_COL);
  381.  
  382.     return(0);
  383.  
  384. }
  385.  
  386.